﻿Imports Relatorio
Imports Persistencia
Imports Controle
Imports System.IO
Public Class frmPrincipal
    Inherits System.Windows.Forms.Form
    Public objUsuario As New perUsuario
    Private objUpdate As New ctrUpdate
    Private sLocal As String = Application.ExecutablePath

    'Usada para validar a versao trial. Não permitir troca de data após a abertura do sistema.
    Public DataStart As Date
    Public ReadOnly Property Local()
        Get
            Return sLocal
        End Get
    End Property
    Private Sub PessoaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PessoaToolStripMenuItem.Click
        Dim frm As New frmCliente
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub EstadoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm As New frmEstado
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub CidadeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm As New frmCidade
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub BairroToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm As New frmBairro
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub RegiãoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm As New frmRegiao
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub StatusToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StatusToolStripMenuItem.Click
        Dim frm As New frmStatus
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub DepartamentoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm As New frmDepartamento
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub ClientesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClientesToolStripMenuItem.Click
        Dim frm As New frmRelClientes
        frm.MdiParent = Me
        frm.Show()
    End Sub
    Private Sub frmPrincipal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim objSeguranca As New Persistencia.perSeguranca
        Dim sArquivoConexao As String = "\SQL.DC"
        Dim sArqUpdate As String = "\DSUpdate.mdb"
        Dim ftmConexao As New frmConexao
        Dim frmTarefa As New frmTarefas
        Dim objSql As New Persistencia.perPadrao
        Dim sMsg As String
        Dim bConexao As Boolean = True
        Dim dtExpiraEm As Date

        Me.Visible = False
        Persistencia.perGlobais.prvLocalExe = Application.StartupPath
        Try
            If (Not (IO.File.Exists(Persistencia.perGlobais.prvLocalExe + sArquivoConexao)) Or Not objSql.TestarConexao) Then
                sMsg = "Não foi possível conectar ao banco de dados."
                MsgBox(sMsg, MsgBoxStyle.Critical)
                bConexao = False
            End If

            If (Not bConexao) Then
                With frmConexao
                    .ShowDialog()
                    If Not (.DialogResult = Windows.Forms.DialogResult.OK) Then
                        Application.Exit()
                        Exit Sub
                    End If
                End With
            End If

            Me.Visible = True
            If (IO.File.Exists(Persistencia.perGlobais.prvLocalExe + sArqUpdate)) Then
                If (objUpdate.AtualizarVersao(Persistencia.perGlobais.prvLocalExe + sArqUpdate)) Then
                    MsgBox("Sistema atualizado com sucesso.", MsgBoxStyle.Exclamation)
                Else
                    MsgBox("Sistema não atualizado.")
                End If
            End If
#If Not Debug Then
        dtExpiraEm = CDate("19/11/2009")
        If (Date.Now > dtExpiraEm) Then
            sMsg = "Versão de teste expirada. Entre em contato com a DevSolutions."
            MsgBox(sMsg)
            Close()
        Else
            If (DateDiff(DateInterval.Day, Date.Now, dtExpiraEm) <= 10) Then
                sMsg = "Versão de teste irá expirar em " & DateDiff(DateInterval.Day, Date.Now, dtExpiraEm) & " dias." & vbCrLf
                sMsg &= "Entre em contato com a DevSolutions."

                MsgBox(sMsg)
            End If
            If (objUsuario.Usuario = 0) Then
                With frmAcesso
                    Me.Visible = False
                    .ShowDialog()
                    If (.DialogResult = Windows.Forms.DialogResult.OK) Then
                        objUsuario.Usuario = .Usuario
                        Me.Visible = True

                    End If
                End With
            End If
        End If

#End If
#If DEBUG Then
            objUsuario.Usuario = 0
#End If
            Persistencia.perGlobais.prvIDUsuario = objUsuario.Usuario

            frmTarefa.MdiParent = Me
            frmTarefa.Show()

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, Me.Text)
        End Try

    End Sub
    Private Sub OcorrênciasToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OcorrênciasToolStripMenuItem1.Click
        Dim frm As New frmOcorrencia
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub

    Private Sub CadastroToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CadastroToolStripMenuItem.Click
        Dim frmUsu As New frmUsuario
        frmUsu.MdiParent = Me
        frmUsu.Show()
    End Sub

    Private Sub ContatosRealizadosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContatosRealizadosToolStripMenuItem.Click
        Dim frmContatosRealizados As New frmRelContatosRealizados
        frmContatosRealizados.MdiParent = Me
        frmRelContatosRealizados.Show()
    End Sub

    Private Sub ContatosARealizarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContatosARealizarToolStripMenuItem.Click
        Dim frmContatosARealizar As New frmContatosARealizar
        frmContatosARealizar.MdiParent = Me
        frmContatosARealizar.Show()
    End Sub

    Private Sub RamoDeAtividadeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RamoDeAtividadeToolStripMenuItem.Click
        Dim frmRamoDeAtividade As New frmRamoAtividade
        frmRamoDeAtividade.MdiParent = Me
        frmRamoDeAtividade.Show()
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbCadCliente.Click

        Dim frmCadCliente As New frmCliente
        frmCliente.MdiParent = Me
        frmCadCliente.Show()

    End Sub

    Private Sub tsbCadContato_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbCadContato.Click

        Dim frmContAgendado As New frmContatoAgendado
        frmContAgendado.ShowDialog()

    End Sub

    Private Sub frmPrincipal_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize


    End Sub
    Private Sub ConfiguraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfiguraToolStripMenuItem.Click

        frmConfiguracoes.MdiParent = Me
        frmConfiguracoes.Show()

    End Sub
    Private Sub tsbVisita_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbVisita.Click

        frmCadVisitas.ShowDialog()

    End Sub
    Private Sub BairroToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BairroToolStripMenuItem1.Click
        frmBairro.MdiParent = Me
        frmBairro.Show()
    End Sub
    Private Sub CidadeToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CidadeToolStripMenuItem1.Click
        frmCidade.MdiParent = Me
        frmCidade.Show()
    End Sub
    Private Sub EstadoToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EstadoToolStripMenuItem1.Click
        frmEstado.MdiParent = Me
        frmEstado.Show()
    End Sub
    Private Sub RegiáoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RegiáoToolStripMenuItem.Click
        frmRegiao.MdiParent = Me
        frmRegiao.Show()
    End Sub

    Private Sub tsbAgendaVisitas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbAgendaVisitas.Click
        frmAgendaVisita.MdiParent = Me
        frmAgendaVisita.Show()
    End Sub

    Private Sub VisitasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VisitasToolStripMenuItem.Click
        frmRelVisitas.MdiParent = Me
        frmRelVisitas.Show()
    End Sub

    Private Sub DepartamentoToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DepartamentoToolStripMenuItem.Click
        frmDepartamento.MdiParent = Me
        frmDepartamento.Show()
    End Sub

    Private Sub TarefasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TarefasToolStripMenuItem.Click
        frmTarefas.MdiParent = Me
        frmTarefas.Show()
    End Sub

    Private Sub AgendarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AgendarToolStripMenuItem.Click
        frmCadVisitas.MdiParent = Me
        frmCadVisitas.Show()
    End Sub

    Private Sub HistóricoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HistóricoToolStripMenuItem.Click
        frmHistVisita.MdiParent = Me
        frmHistVisita.Show()
    End Sub

    Private Sub SetorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetorToolStripMenuItem.Click
        frmSetores.MdiParent = Me
        frmSetores.Show()
    End Sub

    Private Sub tsbServicos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbServicos.Click
        frmOrdemServico.MdiParent = Me
        frmOrdemServico.Show()
    End Sub

    Private Sub tsbOcorrencias_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbOcorrencias.Click
        frmOcorrencia.MdiParent = Me
        frmOcorrencia.Show()
    End Sub

    Private Sub PesquisaToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PesquisaToolStripMenuItem1.Click

        frmConsultaLig.MdiParent = Me
        frmConsultaLig.Show()

    End Sub

    Private Sub AgendarToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AgendarToolStripMenuItem1.Click

        frmContatoAgendado.MdiParent = Me
        frmContatoAgendado.Show()

    End Sub
End Class